package main

import (
	"fmt"
	"log"
	"net/http"
	"ztchat/global"

	"os"
	"os/exec"
)

const (
	SEND_PORT   = 8999
	LISTEN_PORT = 9000
)

func initWX() {
	injectToolPath := "./tool/dfg/inject_tool.exe"

	if _, err := os.Stat(injectToolPath); os.IsNotExist(err) {
		log.Fatalf("Error: %s does not exist\n", injectToolPath)
	}

	cmd := exec.Command(
		injectToolPath,
		"start",
		fmt.Sprint(SEND_PORT),
		fmt.Sprintf("--my_port=%d", LISTEN_PORT),
	)

	output, err := cmd.CombinedOutput()
	if err != nil {
		log.Fatalf("Error executing command: %v\n", err)
	}

	utf8Output, err := global.GbkToUtf8(output)
	if err != nil {
		log.Fatalf("Error converting output to UTF-8: %v\n", err)
	}

	log.Printf("注入结果：%s\n", utf8Output)
}

func main() {
	// initWX()

	client := &http.Client{}

	if isLoginOnce(client) {
		global.CurrentUser = getInfo(client)
	}

	var users []ListDetail
	var groups []ListDetail

	users = getUserList(client)
	groups = getGroupList(client)

	log.Printf("current user: %+v\n\n", global.CurrentUser)
	log.Printf("users: %+v\n\n", users)
	log.Printf("groups: %+v\n\n", groups)

  // sendTextEveryOne(client, users)
  // sendTextEveryOne(client, groups)

	// loginTicker := time.NewTicker(5 * time.Second)
	// defer loginTicker.Stop()
	//
	/// var apiTicker *time.Ticker

	// go listenForDLLSignal()

	// go func() {
	// 	for {
	// 		select {
	// 		case <-loginTicker.C:
	// 			if isLogin(client, loginTicker) {
	// 				apiTicker = time.NewTicker(10 * time.Second)
	// 				defer apiTicker.Stop()
	//
	// 				for range apiTicker.C {
	// 					log.Println("request")
	// 				}
	// 				return
	// 			}
	// 		}
	// 	}
	// }()

	// select {}
}
